package com.opal.reporforms.controller;

import com.opal.domain.ReturnMessageData;
import com.opal.model.DataGridData;
import com.opal.reporforms.service.ThreeBomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/reportForms")
public class ThreeBomController {
    @Autowired
    private ThreeBomService threeBomService;

    /**
     * 导出excel BOM
     * @param BOMs BOM共三联：数量
     * @return
     */
    @RequestMapping("/printBom")
    @ResponseBody
    public List<Object> printBom( String[] BOMs, HttpServletRequest request, HttpServletResponse response){
        ReturnMessageData service=threeBomService.printBomService(BOMs,request,response);
        return null ;
    }
    /**
     * 获取组织
     * @return
     */
    @RequestMapping("/getPkFactory")
    @ResponseBody
    public List<Object> getPkFactory(){
        ReturnMessageData service = threeBomService.getPkFactoryService();
        List<Object> list = (List<Object>)service.getData();
        return list;
    }

    /**
     * 获取物料名字：为null，未找到
     * @return
     */
    @RequestMapping("/getBdMaterialByCode")
    @ResponseBody
    public Object getBdMaterialByCode(String code){
        ReturnMessageData service = threeBomService.getBdMaterialByCodeService(code);
        return service;
    }

    /**
     * 获取物料第一联打印详情（分页）
     * @return
     */
    @RequestMapping("/selectOneFormPage")
    @ResponseBody
    public Object selectOneFormControllerPage(String pkOrg, String code, DataGridData rmd){
        DataGridData dataGrid = threeBomService.selectOneFormService(pkOrg, code,rmd);
        return dataGrid;
    }

    /**
     * 获取物料第一联打印详情
     * @return
     */
    @RequestMapping("/selectOneForm")
    @ResponseBody
    public Object selectOneFormController(String pkOrg,String code){
        DataGridData dataGrid = threeBomService.selectOneFormService(pkOrg, code);
        return dataGrid;
    }

    /**
     * 获取物料第二联打印详情
     * @return
     */
    @RequestMapping("/selectTwoForm")
    @ResponseBody
    public Object selectTwoFormController(String pkOrg,String code){
        DataGridData dataGrid = threeBomService.selectTwoFormService(pkOrg, code);
        return dataGrid;
    }

    /**
     * 获取物料第三联打印详情
     * @return
     */
    @RequestMapping("/selectThreeForm")
    @ResponseBody
    public Object selectThreeFormController(String pkOrg,String code){
        DataGridData dataGrid = threeBomService.selectThreeFormService(pkOrg, code);
        return dataGrid;
    }

    @RequestMapping("{page}")
    public String skipPage(@PathVariable("page") String page) {
        return "reportForms/" + page;
    }

}
